.class public Lorg/microemu/microedition/ImplFactory;
.super Ljava/lang/Object;
.source "ImplFactory.java"


# annotations
.annotation system Ldalvik/annotation/MemberClasses;
    value = {
        Lorg/microemu/microedition/ImplFactory$SingletonHolder;
    }
.end annotation


# static fields
.field public static final DEFAULT:Ljava/lang/String; = "org.microemu.default"

.field private static final IMPLEMENTATION_NAME_SUFIX:Ljava/lang/String; = "Impl"

.field private static final INTERFACE_NAME_SUFIX:Ljava/lang/String; = "Delegate"

.field static class$org$microemu$microedition$ImplFactory:Ljava/lang/Class;

.field static class$org$microemu$microedition$io$ConnectorDelegate:Ljava/lang/Class;


# instance fields
.field private acc:Ljava/security/AccessControlContext;

.field private implementations:Ljava/util/Map;

.field private implementationsGCF:Ljava/util/Map;


# direct methods
.method private constructor <init>()V
    .locals 1

    .prologue
    .line 66
    invoke-direct {p0}, Ljava/lang/Object;-><init>()V

    .line 51
    new-instance v0, Ljava/util/HashMap;

    invoke-direct {v0}, Ljava/util/HashMap;-><init>()V

    iput-object v0, p0, Lorg/microemu/microedition/ImplFactory;->implementations:Ljava/util/Map;

    .line 53
    new-instance v0, Ljava/util/HashMap;

    invoke-direct {v0}, Ljava/util/HashMap;-><init>()V

    iput-object v0, p0, Lorg/microemu/microedition/ImplFactory;->implementationsGCF:Ljava/util/Map;

    .line 67
    invoke-static {}, Ljava/security/AccessController;->getContext()Ljava/security/AccessControlContext;

    move-result-object v0

    iput-object v0, p0, Lorg/microemu/microedition/ImplFactory;->acc:Ljava/security/AccessControlContext;

    .line 68
    return-void
.end method

.method constructor <init>(Lorg/microemu/microedition/ImplFactory$1;)V
    .locals 0
    .parameter "x0"

    .prologue
    .line 43
    invoke-direct {p0}, Lorg/microemu/microedition/ImplFactory;-><init>()V

    return-void
.end method

.method static class$(Ljava/lang/String;)Ljava/lang/Class;
    .locals 2
    .parameter "x0"

    .prologue
    .line 95
    :try_start_0
    invoke-static {p0}, Ljava/lang/Class;->forName(Ljava/lang/String;)Ljava/lang/Class;
    :try_end_0
    .catch Ljava/lang/ClassNotFoundException; {:try_start_0 .. :try_end_0} :catch_0

    move-result-object v1

    return-object v1

    :catch_0
    move-exception v0

    .local v0, x1:Ljava/lang/ClassNotFoundException;
    new-instance v1, Ljava/lang/NoClassDefFoundError;

    invoke-direct {v1}, Ljava/lang/NoClassDefFoundError;-><init>()V

    invoke-virtual {v1, v0}, Ljava/lang/NoClassDefFoundError;->initCause(Ljava/lang/Throwable;)Ljava/lang/Throwable;

    move-result-object v1

    throw v1
.end method

.method public static getCGFImplementation(Ljava/lang/String;)Lorg/microemu/microedition/io/ConnectorDelegate;
    .locals 4
    .parameter "name"

    .prologue
    .line 173
    invoke-static {p0}, Lorg/microemu/microedition/ImplFactory;->getCGFScheme(Ljava/lang/String;)Ljava/lang/String;

    move-result-object v1

    .line 174
    .local v1, scheme:Ljava/lang/String;
    invoke-static {}, Lorg/microemu/microedition/ImplFactory;->instance()Lorg/microemu/microedition/ImplFactory;

    move-result-object v2

    iget-object v2, v2, Lorg/microemu/microedition/ImplFactory;->implementationsGCF:Ljava/util/Map;

    invoke-interface {v2, v1}, Ljava/util/Map;->get(Ljava/lang/Object;)Ljava/lang/Object;

    move-result-object v0

    check-cast v0, Lorg/microemu/microedition/io/ConnectorDelegate;

    .line 175
    .local v0, impl:Lorg/microemu/microedition/io/ConnectorDelegate;
    if-eqz v0, :cond_0

    move-object v2, v0

    .line 182
    .end local p0
    :goto_0
    return-object v2

    .line 178
    .restart local p0
    :cond_0
    invoke-static {}, Lorg/microemu/microedition/ImplFactory;->instance()Lorg/microemu/microedition/ImplFactory;

    move-result-object v2

    iget-object v2, v2, Lorg/microemu/microedition/ImplFactory;->implementationsGCF:Ljava/util/Map;

    const-string v3, "org.microemu.default"

    invoke-interface {v2, v3}, Ljava/util/Map;->get(Ljava/lang/Object;)Ljava/lang/Object;

    move-result-object v0

    .end local v0           #impl:Lorg/microemu/microedition/io/ConnectorDelegate;
    check-cast v0, Lorg/microemu/microedition/io/ConnectorDelegate;

    .line 179
    .restart local v0       #impl:Lorg/microemu/microedition/io/ConnectorDelegate;
    if-eqz v0, :cond_1

    move-object v2, v0

    .line 180
    goto :goto_0

    .line 182
    :cond_1
    invoke-static {}, Lorg/microemu/microedition/ImplFactory;->instance()Lorg/microemu/microedition/ImplFactory;

    move-result-object v2

    sget-object v3, Lorg/microemu/microedition/ImplFactory;->class$org$microemu$microedition$io$ConnectorDelegate:Ljava/lang/Class;

    if-nez v3, :cond_2

    const-string v3, "org.microemu.microedition.io.ConnectorDelegate"

    invoke-static {v3}, Lorg/microemu/microedition/ImplFactory;->class$(Ljava/lang/String;)Ljava/lang/Class;

    move-result-object v3

    sput-object v3, Lorg/microemu/microedition/ImplFactory;->class$org$microemu$microedition$io$ConnectorDelegate:Ljava/lang/Class;

    :goto_1
    invoke-direct {v2, v3}, Lorg/microemu/microedition/ImplFactory;->getDefaultImplementation(Ljava/lang/Class;)Ljava/lang/Object;

    move-result-object p0

    .end local p0
    check-cast p0, Lorg/microemu/microedition/io/ConnectorDelegate;

    move-object v2, p0

    goto :goto_0

    .restart local p0
    :cond_2
    sget-object v3, Lorg/microemu/microedition/ImplFactory;->class$org$microemu$microedition$io$ConnectorDelegate:Ljava/lang/Class;

    goto :goto_1
.end method

.method public static getCGFScheme(Ljava/lang/String;)Ljava/lang/String;
    .locals 2
    .parameter "name"

    .prologue
    .line 163
    const/4 v0, 0x0

    const/16 v1, 0x3a

    invoke-virtual {p0, v1}, Ljava/lang/String;->indexOf(I)I

    move-result v1

    invoke-virtual {p0, v0, v1}, Ljava/lang/String;->substring(II)Ljava/lang/String;

    move-result-object v0

    return-object v0
.end method

.method private getDefaultImplementation(Ljava/lang/Class;)Ljava/lang/Object;
    .locals 6
    .parameter "delegateInterface"

    .prologue
    const-string v3, "Delegate"

    .line 123
    :try_start_0
    invoke-virtual {p1}, Ljava/lang/Class;->getName()Ljava/lang/String;

    move-result-object v2

    .line 124
    .local v2, name:Ljava/lang/String;
    const-string v3, "Delegate"

    invoke-virtual {v2, v3}, Ljava/lang/String;->endsWith(Ljava/lang/String;)Z

    move-result v3

    if-eqz v3, :cond_0

    .line 125
    const/4 v3, 0x0

    invoke-virtual {v2}, Ljava/lang/String;->length()I

    move-result v4

    const-string v5, "Delegate"

    invoke-virtual {v5}, Ljava/lang/String;->length()I

    move-result v5

    sub-int/2addr v4, v5

    invoke-virtual {v2, v3, v4}, Ljava/lang/String;->substring(II)Ljava/lang/String;

    move-result-object v2

    .line 127
    :cond_0
    new-instance v3, Ljava/lang/StringBuffer;

    invoke-direct {v3}, Ljava/lang/StringBuffer;-><init>()V

    invoke-virtual {v3, v2}, Ljava/lang/StringBuffer;->append(Ljava/lang/String;)Ljava/lang/StringBuffer;

    move-result-object v3

    const-string v4, "Impl"

    invoke-virtual {v3, v4}, Ljava/lang/StringBuffer;->append(Ljava/lang/String;)Ljava/lang/StringBuffer;

    move-result-object v3

    invoke-virtual {v3}, Ljava/lang/StringBuffer;->toString()Ljava/lang/String;

    move-result-object v1

    .line 128
    .local v1, implClassName:Ljava/lang/String;
    new-instance v3, Lorg/microemu/microedition/ImplFactory$1;

    invoke-direct {v3, p0, v1}, Lorg/microemu/microedition/ImplFactory$1;-><init>(Lorg/microemu/microedition/ImplFactory;Ljava/lang/String;)V

    iget-object v4, p0, Lorg/microemu/microedition/ImplFactory;->acc:Ljava/security/AccessControlContext;

    invoke-static {v3, v4}, Ljava/security/AccessController;->doPrivileged(Ljava/security/PrivilegedExceptionAction;Ljava/security/AccessControlContext;)Ljava/lang/Object;
    :try_end_0
    .catch Ljava/lang/Throwable; {:try_start_0 .. :try_end_0} :catch_0

    move-result-object v3

    return-object v3

    .line 139
    .end local v2           #name:Ljava/lang/String;
    .end local v1           #implClassName:Ljava/lang/String;
    :catch_0
    move-exception v3

    move-object v0, v3

    .line 140
    .local v0, e:Ljava/lang/Throwable;
    new-instance v3, Ljava/lang/RuntimeException;

    new-instance v4, Ljava/lang/StringBuffer;

    invoke-direct {v4}, Ljava/lang/StringBuffer;-><init>()V

    const-string v5, "Unable create "

    invoke-virtual {v4, v5}, Ljava/lang/StringBuffer;->append(Ljava/lang/String;)Ljava/lang/StringBuffer;

    move-result-object v4

    invoke-virtual {p1}, Ljava/lang/Class;->getName()Ljava/lang/String;

    move-result-object v5

    invoke-virtual {v4, v5}, Ljava/lang/StringBuffer;->append(Ljava/lang/String;)Ljava/lang/StringBuffer;

    move-result-object v4

    const-string v5, " implementation"

    invoke-virtual {v4, v5}, Ljava/lang/StringBuffer;->append(Ljava/lang/String;)Ljava/lang/StringBuffer;

    move-result-object v4

    invoke-virtual {v4}, Ljava/lang/StringBuffer;->toString()Ljava/lang/String;

    move-result-object v4

    invoke-direct {v3, v4, v0}, Ljava/lang/RuntimeException;-><init>(Ljava/lang/String;Ljava/lang/Throwable;)V

    throw v3
.end method

.method public static getImplementation(Ljava/lang/Class;Ljava/lang/Class;)Lorg/microemu/microedition/Implementation;
    .locals 2
    .parameter "origClass"
    .parameter "delegateInterface"

    .prologue
    .line 195
    invoke-static {}, Lorg/microemu/microedition/ImplFactory;->instance()Lorg/microemu/microedition/ImplFactory;

    move-result-object v1

    iget-object v1, v1, Lorg/microemu/microedition/ImplFactory;->implementations:Ljava/util/Map;

    invoke-interface {v1, p1}, Ljava/util/Map;->get(Ljava/lang/Object;)Ljava/lang/Object;

    move-result-object v0

    .line 201
    .local v0, impl:Ljava/lang/Object;
    if-eqz v0, :cond_1

    .line 202
    instance-of v1, v0, Ljava/lang/Class;

    if-eqz v1, :cond_0

    .line 203
    invoke-static {}, Lorg/microemu/microedition/ImplFactory;->instance()Lorg/microemu/microedition/ImplFactory;

    move-result-object v1

    check-cast v0, Ljava/lang/Class;

    .end local v0           #impl:Ljava/lang/Object;
    invoke-direct {v1, v0}, Lorg/microemu/microedition/ImplFactory;->implementationNewInstance(Ljava/lang/Class;)Ljava/lang/Object;

    move-result-object p0

    .end local p0
    check-cast p0, Lorg/microemu/microedition/Implementation;

    move-object v1, p0

    .line 208
    :goto_0
    return-object v1

    .line 205
    .restart local v0       #impl:Ljava/lang/Object;
    .restart local p0
    :cond_0
    check-cast v0, Lorg/microemu/microedition/Implementation;

    .end local v0           #impl:Ljava/lang/Object;
    move-object v1, v0

    goto :goto_0

    .line 208
    .restart local v0       #impl:Ljava/lang/Object;
    :cond_1
    invoke-static {}, Lorg/microemu/microedition/ImplFactory;->instance()Lorg/microemu/microedition/ImplFactory;

    move-result-object v1

    invoke-direct {v1, p1}, Lorg/microemu/microedition/ImplFactory;->getDefaultImplementation(Ljava/lang/Class;)Ljava/lang/Object;

    move-result-object p0

    .end local p0
    check-cast p0, Lorg/microemu/microedition/Implementation;

    move-object v1, p0

    goto :goto_0
.end method

.method private implementationNewInstance(Ljava/lang/Class;)Ljava/lang/Object;
    .locals 4
    .parameter "implClass"

    .prologue
    .line 146
    :try_start_0
    new-instance v1, Lorg/microemu/microedition/ImplFactory$2;

    invoke-direct {v1, p0, p1}, Lorg/microemu/microedition/ImplFactory$2;-><init>(Lorg/microemu/microedition/ImplFactory;Ljava/lang/Class;)V

    iget-object v2, p0, Lorg/microemu/microedition/ImplFactory;->acc:Ljava/security/AccessControlContext;

    invoke-static {v1, v2}, Ljava/security/AccessController;->doPrivileged(Ljava/security/PrivilegedExceptionAction;Ljava/security/AccessControlContext;)Ljava/lang/Object;
    :try_end_0
    .catch Ljava/lang/Throwable; {:try_start_0 .. :try_end_0} :catch_0

    move-result-object v1

    return-object v1

    .line 151
    :catch_0
    move-exception v1

    move-object v0, v1

    .line 152
    .local v0, e:Ljava/lang/Throwable;
    new-instance v1, Ljava/lang/RuntimeException;

    new-instance v2, Ljava/lang/StringBuffer;

    invoke-direct {v2}, Ljava/lang/StringBuffer;-><init>()V

    const-string v3, "Unable create "

    invoke-virtual {v2, v3}, Ljava/lang/StringBuffer;->append(Ljava/lang/String;)Ljava/lang/StringBuffer;

    move-result-object v2

    invoke-virtual {p1}, Ljava/lang/Class;->getName()Ljava/lang/String;

    move-result-object v3

    invoke-virtual {v2, v3}, Ljava/lang/StringBuffer;->append(Ljava/lang/String;)Ljava/lang/StringBuffer;

    move-result-object v2

    const-string v3, " implementation"

    invoke-virtual {v2, v3}, Ljava/lang/StringBuffer;->append(Ljava/lang/String;)Ljava/lang/StringBuffer;

    move-result-object v2

    invoke-virtual {v2}, Ljava/lang/StringBuffer;->toString()Ljava/lang/String;

    move-result-object v2

    invoke-direct {v1, v2, v0}, Ljava/lang/RuntimeException;-><init>(Ljava/lang/String;Ljava/lang/Throwable;)V

    throw v1
.end method

.method public static instance()Lorg/microemu/microedition/ImplFactory;
    .locals 1

    .prologue
    .line 71
    invoke-static {}, Lorg/microemu/microedition/ImplFactory$SingletonHolder;->access$100()Lorg/microemu/microedition/ImplFactory;

    move-result-object v0

    return-object v0
.end method

.method public static register(Ljava/lang/Class;Ljava/lang/Class;)V
    .locals 1
    .parameter "delegate"
    .parameter "implementationClass"

    .prologue
    .line 75
    invoke-static {}, Lorg/microemu/microedition/ImplFactory;->instance()Lorg/microemu/microedition/ImplFactory;

    move-result-object v0

    iget-object v0, v0, Lorg/microemu/microedition/ImplFactory;->implementations:Ljava/util/Map;

    invoke-interface {v0, p0, p1}, Ljava/util/Map;->put(Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object;

    .line 76
    return-void
.end method

.method public static register(Ljava/lang/Class;Ljava/lang/Object;)V
    .locals 1
    .parameter "delegate"
    .parameter "implementationInstance"

    .prologue
    .line 79
    invoke-static {}, Lorg/microemu/microedition/ImplFactory;->instance()Lorg/microemu/microedition/ImplFactory;

    move-result-object v0

    iget-object v0, v0, Lorg/microemu/microedition/ImplFactory;->implementations:Ljava/util/Map;

    invoke-interface {v0, p0, p1}, Ljava/util/Map;->put(Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object;

    .line 80
    return-void
.end method

.method public static registerGCF(Ljava/lang/String;Ljava/lang/Object;)V
    .locals 3
    .parameter "scheme"
    .parameter "implementation"

    .prologue
    .line 95
    sget-object v1, Lorg/microemu/microedition/ImplFactory;->class$org$microemu$microedition$io$ConnectorDelegate:Ljava/lang/Class;

    if-nez v1, :cond_0

    const-string v1, "org.microemu.microedition.io.ConnectorDelegate"

    invoke-static {v1}, Lorg/microemu/microedition/ImplFactory;->class$(Ljava/lang/String;)Ljava/lang/Class;

    move-result-object v1

    sput-object v1, Lorg/microemu/microedition/ImplFactory;->class$org$microemu$microedition$io$ConnectorDelegate:Ljava/lang/Class;

    :goto_0
    invoke-virtual {p1}, Ljava/lang/Object;->getClass()Ljava/lang/Class;

    move-result-object v2

    invoke-virtual {v1, v2}, Ljava/lang/Class;->isAssignableFrom(Ljava/lang/Class;)Z

    move-result v1

    if-nez v1, :cond_1

    .line 96
    new-instance v1, Ljava/lang/IllegalArgumentException;

    invoke-direct {v1}, Ljava/lang/IllegalArgumentException;-><init>()V

    throw v1

    .line 95
    :cond_0
    sget-object v1, Lorg/microemu/microedition/ImplFactory;->class$org$microemu$microedition$io$ConnectorDelegate:Ljava/lang/Class;

    goto :goto_0

    .line 98
    :cond_1
    if-nez p0, :cond_2

    .line 99
    const-string p0, "org.microemu.default"

    .line 101
    :cond_2
    invoke-static {}, Lorg/microemu/microedition/ImplFactory;->instance()Lorg/microemu/microedition/ImplFactory;

    move-result-object v1

    iget-object v1, v1, Lorg/microemu/microedition/ImplFactory;->implementationsGCF:Ljava/util/Map;

    invoke-interface {v1, p0}, Ljava/util/Map;->get(Ljava/lang/Object;)Ljava/lang/Object;

    move-result-object v0

    .line 102
    .local v0, impl:Ljava/lang/Object;
    instance-of v1, v0, Lorg/microemu/microedition/ImplementationUnloadable;

    if-eqz v1, :cond_3

    .line 103
    check-cast v0, Lorg/microemu/microedition/ImplementationUnloadable;

    .end local v0           #impl:Ljava/lang/Object;
    invoke-interface {v0}, Lorg/microemu/microedition/ImplementationUnloadable;->unregisterImplementation()V

    .line 105
    :cond_3
    invoke-static {}, Lorg/microemu/microedition/ImplFactory;->instance()Lorg/microemu/microedition/ImplFactory;

    move-result-object v1

    iget-object v1, v1, Lorg/microemu/microedition/ImplFactory;->implementationsGCF:Ljava/util/Map;

    invoke-interface {v1, p0, p1}, Ljava/util/Map;->put(Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object;

    .line 106
    return-void
.end method

.method public static unregistedGCF(Ljava/lang/String;Ljava/lang/Object;)V
    .locals 3
    .parameter "scheme"
    .parameter "implementation"

    .prologue
    .line 109
    sget-object v1, Lorg/microemu/microedition/ImplFactory;->class$org$microemu$microedition$io$ConnectorDelegate:Ljava/lang/Class;

    if-nez v1, :cond_0

    const-string v1, "org.microemu.microedition.io.ConnectorDelegate"

    invoke-static {v1}, Lorg/microemu/microedition/ImplFactory;->class$(Ljava/lang/String;)Ljava/lang/Class;

    move-result-object v1

    sput-object v1, Lorg/microemu/microedition/ImplFactory;->class$org$microemu$microedition$io$ConnectorDelegate:Ljava/lang/Class;

    :goto_0
    invoke-virtual {p1}, Ljava/lang/Object;->getClass()Ljava/lang/Class;

    move-result-object v2

    invoke-virtual {v1, v2}, Ljava/lang/Class;->isAssignableFrom(Ljava/lang/Class;)Z

    move-result v1

    if-nez v1, :cond_1

    .line 110
    new-instance v1, Ljava/lang/IllegalArgumentException;

    invoke-direct {v1}, Ljava/lang/IllegalArgumentException;-><init>()V

    throw v1

    .line 109
    :cond_0
    sget-object v1, Lorg/microemu/microedition/ImplFactory;->class$org$microemu$microedition$io$ConnectorDelegate:Ljava/lang/Class;

    goto :goto_0

    .line 112
    :cond_1
    if-nez p0, :cond_2

    .line 113
    const-string p0, "org.microemu.default"

    .line 115
    :cond_2
    invoke-static {}, Lorg/microemu/microedition/ImplFactory;->instance()Lorg/microemu/microedition/ImplFactory;

    move-result-object v1

    iget-object v1, v1, Lorg/microemu/microedition/ImplFactory;->implementationsGCF:Ljava/util/Map;

    invoke-interface {v1, p0}, Ljava/util/Map;->get(Ljava/lang/Object;)Ljava/lang/Object;

    move-result-object v0

    .line 116
    .local v0, impl:Ljava/lang/Object;
    if-ne v0, p1, :cond_3

    .line 117
    invoke-static {}, Lorg/microemu/microedition/ImplFactory;->instance()Lorg/microemu/microedition/ImplFactory;

    move-result-object v1

    iget-object v1, v1, Lorg/microemu/microedition/ImplFactory;->implementationsGCF:Ljava/util/Map;

    invoke-interface {v1, p0}, Ljava/util/Map;->remove(Ljava/lang/Object;)Ljava/lang/Object;

    .line 119
    :cond_3
    return-void
.end method

.method public static unregister(Ljava/lang/Class;Ljava/lang/Class;)V
    .locals 0
    .parameter "delegate"
    .parameter "implementation"

    .prologue
    .line 84
    return-void
.end method
